package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.CornerPathEffect
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* AodiLogoView
* */
class AodiLogoView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_CF85F4)
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat()
            val cy = mHeight.toFloat() / 2

            val mStrokeWidth = (cx / 40).coerceAtLeast(minStrokeWidth)
            mPaint0.strokeWidth = mStrokeWidth

            drawCircle(
                cx * 1 / 100 + cx * 98 / 100 / 4 / 2 + cx * 9 / 200,
                cy,
                cx * 98 / 100 / 4 / 2 - mStrokeWidth / 2 + cx * 9 / 200,
                mPaint0
            )

            drawCircle(
                cx * 1 / 100 + cx * 98 / 100 / 4 + cx * 98 / 100 / 4 / 2 - cx * 12 / 100 + cx * 18 / 100 - cx * 9 / 200,
                cy,
                cx * 98 / 100 / 4 / 2 - mStrokeWidth / 2 + cx * 9 / 200,
                mPaint0
            )

            drawCircle(
                cx * 1 / 100 + cx * 98 / 100 / 4 * 2 + cx * 98 / 100 / 4 / 2 - cx * 24 / 100 + cx * 27 / 100 - cx * 9 / 200,
                cy,
                cx * 98 / 100 / 4 / 2 - mStrokeWidth / 2 + cx * 9 / 200,
                mPaint0
            )

            drawCircle(
                cx * 1 / 100 + cx * 98 / 100 / 4 * 3 + cx * 98 / 100 / 4 / 2 - cx * 36 / 100 + cx * 36 / 100 - cx * 9 / 200,
                cy,
                cx * 98 / 100 / 4 / 2 - mStrokeWidth / 2 + cx * 9 / 200,
                mPaint0
            )
        }
    }
}